# Semaphore 控制进程的并发量

import multiprocessing
import os
import random
import time
def fn(sem):
    while sem:
        pname = multiprocessing.current_process().name
        print("开始进程%s" % pname)
        time.sleep(random.randint(3,8))
        print("\t%s进程结束" % pname)




if __name__ == '__main__':
    #控制进程的最大并发量为3
    sem = multiprocessing.Semaphore(3)
    #一次性创建10个进程
    for i in range(1,11):
        multiprocessing.Process(target=fn,name="番号%d" %i,args=(sem,)).start()